<template>
  <div>
    <!-- 管理卡片 -->
    <el-card class="box-card data-card">
      <div slot="header">
        <span><i class="iconfont icon-dingdan1"></i> 修改品牌信息</span>
      </div>
    </el-card>
    <el-card class="input-card data-card">
      <el-form
        :model="listQuery"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="品牌名称:" prop="name" class="inputs-left">
          <el-input v-model="listQuery.name"></el-input>
        </el-form-item>
        <el-form-item
          label="品牌首字母:"
          prop="first_letter"
          class="inputs-left"
        >
          <el-input v-model="listQuery.first_letter"></el-input>
        </el-form-item>

        <el-form-item label="品牌LOGO:" prop="logo" class="inputs-left">
          <el-input v-model="listQuery.logo"></el-input>
        </el-form-item>
        <el-form-item label="品牌专区大图:" prop="big_pic" class="inputs-left">
          <el-input v-model="listQuery.big_pic"></el-input>
        </el-form-item>
        <el-form-item label="品牌故事:" prop="brand_story" class="inputs-left">
          <el-input
            v-model="listQuery.brand_story"
            class="input-width"
          ></el-input>
        </el-form-item>
        <el-form-item label="排序:" prop="sort" class="inputs-left">
          <el-input v-model="listQuery.sort" class="input-width"></el-input>
        </el-form-item>
        <el-form-item label="是否显示:" prop="show_status" class="inputs-left">
          <el-radio-group v-model="listQuery.show_status">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="品牌制造商:"
          prop="factory_status"
          class="inputs-left"
        >
          <el-radio-group v-model="listQuery.factory_status">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item class="inputs-left">
          <el-button type="primary" @click="submitForm('ruleForm')"
            >立即创建</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
// import {
//   updateBrand,
//   updateBrandFactoryStatus,
//   updateBrandShowStatus,
// } from "@/api/product.js";
import { updateBrand, fetchBrandPageList } from "@/api/product.js";
export default {
  name: "brandupdate",
  data: function () {
    return {
      listQuery: {
        id: "",
        big_pic: "", //大图
        brand_story: "", //品牌故事
        factory_status: 0, //品牌制造商
        first_letter: "", //品牌首字母
        logo: "", //品牌logo
        name: "", //品牌名称
        show_status: 0, //品牌是否显示
        sort: 0, //品牌排序
      },

      rules: {
        name: [
          { required: true, message: "请输入商品名称", trigger: "blur" },
          {
            min: 3,
            max: 100,
            message: "长度在3-100个字符之间",
            trigger: "blur",
          },
        ],
        logo: [
          { required: true, message: "请输入图片链接地址", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getBrandList();
  },
  methods: {
    //获取列表数据
    getBrandList() {
      fetchBrandPageList({ id: this.$route.params.id }).then((res) => {
        console.log(123, res.data);
        this.listQuery = res.data[0];
      });
    },
    submitForm(formName) {
      console.log("表单提交了");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 调用后台接口将数据传给服务器，生成一条新数据
          //表单验证通过
          console.log("表单验证通过", this.listQuery);
  
          updateBrand(this.listQuery).then((res) => {
            console.log(2000, res);
            if (res.msg == "修改成功") {
              this.$message({
                message: "成功修改商品分类",
                duration: 1000,
                type: "success",
              });
            }
            this.$router.push("/pms/brand");
          });
        } else {
          console.log("表单验证没通过");
          return false;
        }
      });
    },
  },
};
</script>

<style>
.input-card {
  width: 760px;

  margin: 20px auto;
}
.demo-ruleForm {
  width: 600px;
  margin: 0px auto;
}
</style>